package concurrency.chapter1;

import java.util.concurrent.*;

/**
 * FileName: CallableDemo
 * Author:   周壮
 * Date:     2020/5/17 17:08
 * Description:
 */
public class CallableDemo implements Callable<String> {
    @Override
    public String call() throws Exception {
        int a = 1;
        int b = 1;
        System.out.println(a + b);
        return "执行结果" + (a + b);
    }

    public static void main(String[] args) {
        try {
            ExecutorService executorService = Executors.newFixedThreadPool(1);
            Future<String> future = executorService.submit(new CallableDemo());
            System.out.println(future.get());
            executorService.shutdown();
            // 注意不应该使用executorService.shutdownNow()， 相当于kill -9
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }


    }
}
